package com.springframework.properties;

import com.springframework.util.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @Author Markburt
 * @Description :
 * @DATE: 2020/4/21
 * @TIME: 下午 05:20
 * @YEAR: 2020
 * @Version :
 **/

@Data
@Slf4j
@ConfigurationProperties(prefix = "jwt")
public class JwtProperties {
    /**
     * 公钥
     */
    private String pubKeyPath;
    private String cookieName;

    private PublicKey publicKey;


    /**
     * @PostContruct：在构造方法执行之后执行该方法
     */
    @PostConstruct
    public void init(){
        try {
            // 获取公钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("初始化公钥失败！", e);
            throw new RuntimeException();
        }
    }
}
